<?php 
require_once ROOT_PATH . '/lib/models/hrfunct/EmpInfo.php';
//require_once ROOT_PATH . '/lib/models/skillmatrix/SkillExpertise.php';
require_once ROOT_PATH . '/lib/models/skillmatrix/SkillGroup.php';
require_once ROOT_PATH . '/lib/models/skillmatrix/SkillIndividual.php';
$expertiseIds = $records['expertise']; 
$empList = SkillIndividual::getEmpSkillInfo($expertiseIds);

$baseURL = './CentralController.php?skillMatrixcode=SkillMatrix';
$skillset = array("None","Basic","Intermediate","Expert");
$skillset = array("None","I","II","III");
//get groups skill
$array = $records['skillmatrix'];
//get users' skill
$userSkills = SkillIndividual::getEmpSkillUsers();

function getValue($list,$userid=null,$expertiseid=null){
	if($userid && $expertiseid){
		foreach($list as $item){
			if($item[0]==$userid && $item[1]==$expertiseid)
				return $item;
		}
		return null;
	}else{
		return null;
	}
}
?>
<script type="text/javascript">
 function returnExport() {
		
		document.standardView.action = '<?php echo $baseURL;?>&action=Export';
		document.standardView.submit();
}

function returnSearch() {
		document.getElementById("skillgroup").value='';
		document.standardView.action = '<?php echo $baseURL;?>&action=Individual';
		document.standardView.submit();
}

function returnSearch2() {
		document.standardView.action = '<?php echo $baseURL;?>&action=Individual';
		document.standardView.submit();
}

</script>

<h2><?php echo "Skill Matrix"; ?><hr/></h2>
<form id="standardView" name="standardView" method="post" action="<?php echo $baseURL;?>&action=Summary">
<div style="padding: 6px;" class="buttons">
	<a href="#" class="button" value="Export" onclick="returnExport(); return false;">Export</a>
<input type="hidden" id="expertises" name="expertises" value ="<?php echo $expertiseIds; ?>" /> 						
</div>
<table style="margin-left: 3px;">
<tr>
	
	<td >						
		<select name="grouptype" id="grouptype" onchange="returnSearch();" >
		<?php if(!isset($records['grouptype']) || $records['grouptype']==''){ ?>
		<option value="" >-Select group type-</option>	
		<option value="1" >Developer</option>
		<option value="2" >QA</option>
		<?php } elseif($records['grouptype']==1){ ?>
		<option value="" >-Select group type-</option>	
		<option selected value="1" >Developer</option>
		<option value="2" >QA</option>
		<?php }else{ ?>
		<option value="" >-Select group type-</option>	
		<option value="1" >Developer</option>
		<option selected value="2" >QA</option>
		<?php } ?>
		</select>
	</td>
	
	<td >						
		<select name="skillgroup" id="skillgroup" onchange="returnSearch2();" >
		<option value="" >-Select skill group-</option>	
		<?php
			if(isset($records['grouptype'])&& $records['grouptype']!=''){
				$allGroups = SkillGroup::getSkillGroupByType($records['grouptype']);
			}
			else{ 
				$allGroups = SkillGroup::getAll();				
			}			
			for($m=0;$m< count($allGroups);$m++) {
				if($records['skillgroup'] && $records['skillgroup'] == $allGroups[$m]->getId() ) {
					echo "<option selected value='" . $allGroups[$m]->getId() ."'>".$allGroups[$m]->getSkillGroupName()."</option>";
				} else {
						echo "<option value='" . $allGroups[$m]->getId() ."'>".$allGroups[$m]->getSkillGroupName()."</option>";			
				}								
			}
		?>
		</select>
	</td>
	<td >
		<?php if($records['lastupdate']==1){ ?>						
			<input type="checkbox" checked name="lastupdate" id="lastupdate" value="1" onchange="returnSearch();"> Show latest update
		<?php }else{ ?>
			<input type="checkbox" name="lastupdate" id="lastupdate" value="1" onchange="returnSearch();"> Show latest update
		<?php }?>
	</td>
</tr>
</table>
<table >
	<tr>
		<td>
		<span style="color: red;font-weight: bold;text-decoration: underline;">Legend</span> 
		</td>	
		<td>
		<span  class="legend">1</span>: <a style="font-style: oblique;" title="Demonstrates introductory understanding and ability and, with guidance, applies the skill in a few simple situations.">Introductory</a>  
		</td>
		<td>
		<span class="legend">2</span>: <a style="font-style: oblique;" title="Demonstrates introductory understanding and ability and, with guidance, applies the skill in a few simple situations.">Basic</a>
		
		</td>
		<td>
		<span class="legend">3</span>: <a style="font-style: oblique;" title="Demonstrates solid knowledge and ability, and can apply the skill with minimal or no guidance in the full range of typical situations. Would require guidance to handle novel or more complex situations.">Intermediate</a>		
		</td>
		<td>
		<span class="legend">4 </span>:<a style="font-style: oblique;" title="Demonstrates advanced knowledge and ability, and can apply the skill in new or complex situations. Guides other professionals.">Advanced</a>		
		</td>
		<td>
		<span class="legend">5</span>: <a style="font-style: oblique;" title="Demonstrates expert knowledge and ability, and can apply the skill in the most complex situations. Develops new approaches, methods or policies in the area. Is recognized as an expert, internally and/or externally. Leads the guidance of other professionals.">Expert</a>			
		</td>
		<td>
		<span class="legend">LU</span>: <a style="font-style: oblique;" >Last Update</a>			
		</td>
		
	</tr>
</table>
<?php if (is_array($array) && count($array)>0) {  ?>	
<table border="0" cellpadding="0" cellspacing="0">
	<tr class="skillMatrix">
	<td class="skillMatrix"></td>
	<td  class="skillMatrix" ></td>
	<?php $colspan = 1; ?>
	<?php for($m=0;$m<count($array);$m++) { ?>
		<?php if(isset($array[$m+1])&& $array[$m+1][2]!= $array[$m][2]){ ?>		
			<td  class="skillMatrixHeader"  colspan="<?php echo $colspan ?>"><?php echo $array[$m][3]; ?></td>
			<?php $colspan = 1; ?>
		<?php }else  $colspan ++;  } ?>
	<td  class="skillMatrixHeader"  colspan="<?php echo $colspan ?>"><?php echo $array[$m-1][3]; ?></td>
	</tr>	
	<tr class="skillMatrix">
	<td class="skillMatrix">#</td>
	<td  class="skillMatrixEmp" valign="middle" align="center" >Employee</td>
	<?php for($m=0;$m<count($array);$m++) { ?>		
		<td  class="skillMatrixTitle" ><div style="height: 80px;overflow-y: auto"><?php echo $array[$m][1] ?><div></td>
	<?php } ?>
	</tr>
	<?php if(count($empList)>0) {?>		
		<?php for($l=0;$l<count($empList);$l++) {?>
			<?php $l%2?$cssClass='odd':$cssClass='even'; ?>
			<?php $emp = $empList[$l]; ?>			
			<tr class="skillMatrix" id="<?php echo $cssClass; ?>">
			<td class="skillMatrix"><?php echo $l+1; ?></td>
			<td  class="skillMatrixName" ><?php echo $emp[0]." ".$emp[2]." ".$emp[1]; ?></td>
			<?php for($m=0;$m<count($array);$m++) { ?>
				<?php $item = getValue($userSkills,$emp[3],$array[$m][0]) ?>
				<?php if($item){ ?>	
						<?php if($item[3]!= '0000-00-00 00:00:00' && $records['lastupdate']==1){ ?>		
							<td  class="skillMatrix" >
								<?php echo $item[2]."<br/>"."(LU:".date('M-d,y',strtotime($item[3])).")"; ?>
							</td>
						<?php }else{ ?>
							<td  class="skillMatrix" ><?php echo $item[2]; ?></td>							
						<?php } ?>
				<?php }else{ ?>
					<td  class="skillMatrix" ></td>
				<?php } ?>	
			<?php } ?>
			</tr>			
		<?php }?>				
	<?php }?>
	<?php if(count($empList)>1) {?>
		<tr class="skillMatrix">
			<td class="skillMatrix"></td>			
				<td  class="skillMatrixName" >Summary</td>		
					<?php for($m=0;$m<count($array);$m++) { ?>				
							<?php $totalSum = SkillUser::getTotalSumaryByExpertise($array[$m][0]); ?>							
							<?php $introductory = $totalSum[0]; ?>																		
							<?php $basic = $totalSum[1]; ?>		
							<?php $intermediate =$totalSum[2]; ?>
							<?php $advanced = $totalSum[3];?>		
							<?php $expertise = $totalSum[4]; ?>
							<?php $total = $introductory+$basic+$intermediate+$expertise +$advanced; ?>								
							<td  class="skillMatrixName" >
								<table style="padding: 0px;margin: 0px;">
									<tr>
										<td style="padding: 0px;margin: 0px;">Introductory</td>
										<td style="padding: 0px;margin: 0px;"><?php echo $introductory; ?></td>
									</tr>									
									<tr>
										<td style="padding: 0px;margin: 0px;">Basic</td>
										<td style="padding: 0px;margin: 0px;"><?php echo $basic; ?></td>
									</tr>
									<tr>
										<td style="padding: 0px;margin: 0px;">Intermediate</td>
										<td style="padding: 0px;margin: 0px;"><?php echo $intermediate; ?></td>
									</tr>
									<tr >
										<td style="padding: 0px;margin: 0px; ">Advanced</td>
										<td style="padding: 0px;margin: 0px; " ><?php echo $advanced; ?>	</td>
									</tr>
									<tr >
										<td style="padding: 0px;margin: 0px; border-bottom: 1px solid #D0D0D0;">Expert</td>
										<td style="padding: 0px;margin: 0px; border-bottom: 1px solid #D0D0D0;" ><?php echo $expertise; ?>	</td>
									</tr>
									<tr>
										<td style="padding: 0px;margin: 0px;">Total</td>
										<td style="padding: 0px;margin: 0px;"><?php echo $total; ?>	</td>
									</tr>
								</table>
							</td>	
						<?php } ?>
			</tr>				
	<?php }?>
	
	
</table>
<table class="legend" cellpadding="0" cellspacing="0" style="border: 1px solid #D0D0D0;margin-top: 10px;">
	<tr>
		<td>
		<span style="color: red;font-weight: bold;text-decoration: underline">Skill level description</span> 
		</td>
	</tr>
	<tr>	
		<td>
		1.Introductory:
		<br> 
		<span style="padding-left: 10px;font-weight: normal;">Demonstrates introductory understanding and ability and, with guidance, applies the skill in a few simple situations.</span>  
		</td>
	</tr>
	<tr>		
		<td>
		2.Basic: <br> 
		<span style="padding-left: 10px;font-weight: normal;">Demonstrates basic knowledge and ability and, with guidance, can apply the skill in common situations that present limited difficulties.</span> 
		</td>
	</tr>
	<tr>	
		<td>
		3.Intermediate: <br> 
		<span style="padding-left: 10px;font-weight: normal;">Demonstrates solid knowledge and ability, and can apply the skill with minimal or no guidance in the full range of typical situations. Would require guidance to handle novel or more complex situations.</span>
		
		</td>
		
	</tr>
	<tr>	
		<td>
		4.Advanced: <br> 
		<span style="padding-left: 10px;font-weight: normal;">Demonstrates advanced knowledge and ability, and can apply the skill in new or complex situations. Guides other professionals.</span>		 
		</td>		
	</tr>
	<tr>	
		<td>
		5.Expert: <br> 
		<span style="padding-left: 10px;font-weight: normal;">Demonstrates expert knowledge and ability, and can apply the skill in the most complex situations. Develops new approaches, methods or policies in the area. Is recognized as an expert, internally and/or externally. Leads the guidance of other professionals. </span>
		</td>		
	</tr>
</table>
<?php }  ?>	

 
